package com.miyake.dsp.osa.lab.ui;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

import com.miyake.dsp.ui.LineChartPanel;

public class ChartFrame extends JFrame {
	private LineChartPanel chart;
	public ChartFrame(String name) {
		this.setTitle("Chart");
		chart = new LineChartPanel(name);
		this.setSize(new Dimension(400, 350));
		JPanel p = new JPanel();
		JButton autoRangeButton = new JButton("Fix Range");
		p.add(autoRangeButton);
		autoRangeButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				chart.setAutoRange(false);
			}
		});
		
		JButton clearButton = new JButton("Clear");
		p.add(clearButton);
		clearButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				chart.removeAllTrace();
			}
		});
		
		this.getContentPane().setLayout(new BorderLayout());
		this.getContentPane().add(p, BorderLayout.NORTH);
		this.getContentPane().add(chart, BorderLayout.CENTER);
		this.setAlwaysOnTop(true);
	}


	public synchronized void setData(String key, double[] data) {
		//chart.removeAllTrace();
		chart.setData(key, data);
	}

	public Integer getCurveCount() {
		// TODO Auto-generated method stub
		return chart.getCurveCount();
	}

	public LineChartPanel getChart() {
		return this.chart;
	}
}
